<?php

class Application_Model_Banner {

    private $db = NULL;

    public function __construct() {
        $this->db = new Application_Model_DbTable_Banner();
    }

    public function add(Application_Model_DAO_Banner $banner) {

        $id = $banner->getIdBanner();
        $return = NULL;

        if (empty($id)) {
            $return = $this->db->insert(
                    array(
                        'codUsuario' => $banner->getCodUsuario(),
                        'resolucao' => $banner->getResolucao(),
                        'localizacao' => $banner->getLocalizacao(),
                        'titulo' => $banner->getTitulo(),
                        'imagePath' => $banner->getImagePath(),
                        'status' => $banner->getStatus()
                    )
            );
        } else {
            $return = $this->db->update(
                    array(
                'codUsuario' => $banner->getCodUsuario(),
                'resolucao' => $banner->getResolucao(),
                'localizacao' => $banner->getLocalizacao(),
                'titulo' => $banner->getTitulo(),
                'imagePath' => $banner->getImagePath(),
                'status' => $banner->getStatus())
                    , 'idBanner = ' . (int) $banner->getIdBanner());
        }

        return $return;
    }

    public function alterarStatusBanner(Application_Model_DAO_Banner $dao) {
        $return = $this->db->update(array('status' => (int) $dao->getStatus()), 'idBanner=' . $dao->getIdBanner());
        return $return;
    }

}

